package thread.baohecelue;

import java.util.concurrent.*;

public class Main {

    // 基本线程2个，最大线程3个，工作队列容量为5，饱和策略为 AbortPolicy
    ExecutorService exec = new ThreadPoolExecutor(2, 3, 0L, TimeUnit.SECONDS,
            new LinkedBlockingDeque<Runnable>(5), new ThreadPoolExecutor.AbortPolicy());
    private void putrunnable() {
        for (int i = 0; i < 10; i++) {
            exec.submit(new Task());
        }
        exec.shutdown();
    }

    static class Task implements Runnable {
        private static int count = 0;
        private int id = 0;
        public Task() {
            id = ++count;
        }
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("任务" + id + ":" + Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        new Main().putrunnable();
    }

}
